#include <stdio.h>
#include <stdlib.h>


typedef struct linknode
{
    int data;
    struct linknode *next;
}link_node;

link_node *creat()
{
    link_node *H=(link_node *)malloc(sizeof(link_node));
    H->data=0;
    H->next=NULL;

    return H;
}

int insert(link_node *H,int mydata)
{
    link_node *p=(link_node *)malloc(sizeof(link_node));
    link_node *q=H;
    while(H->next!=NULL)
    {   
        H=H->next;
    }   
    p->next=NULL;
    H->next=p;
    p->data=mydata;
    q->data++;

    return 0;
}                                                                                                                                                                                                                                                                               

int view(link_node *H) 
{
    link_node *p=H;
    while(p->next!=NULL)
    {   
        p=p->next;
        printf("%d ",p->data);

    }   
    putchar(10);

    return 0;
}

void linkopear(link_node *H)
{
	link_node *p=H->next;
	link_node *P=H;
	link_node *a=NULL;
	while(p->next!=NULL&&p->next->next!=NULL)
	{
		while(P->next->next!=NULL)
		{
			P=P->next;
		}
		a=P->next;
//		printf("H->data:%d\n",p->data);
//		printf("P->data:%d a->data:%d\n",P->data,a->data);
		P->next=a->next;
		a->next=p->next;
		p->next=a;
		p=p->next->next;
		P=p;
	}
}


int main(int argc, const char *argv[])
{
	link_node *H=creat();
	insert(H,1);
	insert(H,2);
	insert(H,3);
	insert(H,4);
	insert(H,5);

	view(H);

	linkopear(H);
	view(H);

	return 0;
}
